package com.ysd.lis.service.bac.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.dto.bac.BacAntClassDto;
import com.ysd.lis.entity.bac.BacAntSubClass;
import com.ysd.lis.entity.sta.StaModuleUpgrade;
import com.ysd.lis.mapper.bac.BacAntSubClassMapper;
import com.ysd.lis.request.bac.BacAntClassParam;
import com.ysd.lis.service.bac.BacAntSubClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * cold_chain.sys_module 服务实现类
 * </p>
 *
 * @author prs
 * @since 2024-12-27
 */
@Service
public class BacAntSubClassServiceImpl extends ServiceImpl<BacAntSubClassMapper, BacAntSubClass> implements BacAntSubClassService {
    @Autowired
    BacAntSubClassMapper bacAntSubClassMapper;
    @Override
    public Result findBacAntSubClassList(BacAntClassParam param) {
        MPJLambdaWrapper<BacAntSubClass> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(BacAntSubClass.class);
        if (StringUtils.isNotBlank(param.getAntClassNo())) {
            queryWrapper.eq(BacAntSubClass::getAntClassNo,param.getAntClassNo());
        }

        queryWrapper.eq(StaModuleUpgrade::getDelFlag, 0)
                .orderByAsc(StaModuleUpgrade::getSeq);
        return Result.succ(1, "查询成功", bacAntSubClassMapper.selectList(queryWrapper));

    }

    @Override
    public Result saveOrUpdateBacAntSubClass(BacAntClassDto dto) {
        List<BacAntSubClass> bacAntSubClassList = dto.getBacAntSubClassList();
        boolean b = this.saveOrUpdateBatch(bacAntSubClassList);
        if(b){
            return Result.succ(1, "成功", null);
        }else {
            return Result.fail(400,"失败","");
        }
    }

    @Override
    public Result batchDeleteBacAntSubClassList(BacAntClassDto dto) {
        List<BacAntSubClass> bacAntSubClassList = dto.getBacAntSubClassList();

        List<String> ids = bacAntSubClassList.stream().map(BacAntSubClass::getId).collect(Collectors.toList());
        boolean b = this.removeByIds(ids);
        if(b){
            return Result.succ(1, "删除成功", null);
        }else {
            return Result.fail(400,"删除失败","");
        }
    }
}
